<?php

namespace app\common\model\knowbase;

use app\admin\model\AuthGroup;
use think\Model;
use traits\model\SoftDelete;

class ProjectPageTemplateGroupAccess extends Model
{


   
    protected $name = 'knowbase_project_page_template_group_access';

   
    protected $autoWriteTimestamp = false;

   
    protected $createTime = false;
    protected $updateTime = false;

    public function authGroup()
    {
        return $this->belongsTo(AuthGroup::class, 'group_id')->setEagerlyType(0);
    }
    
    public static function updateAccess($project_page_template_id, $groups)
    {
        self::where('project_page_template_id', $project_page_template_id)->delete();
        foreach (knowbase_splitbyid($groups) as $group_id) {
            self::create(
                [
                    'project_page_template_id' => $project_page_template_id,
                    'group_id'   => $group_id,
                ]
            );
        }
    }
}
